package cn.hrlly.tao2shou.biz;

import android.content.Context;

import com.zhy.http.okhttp.OkHttpUtils;

import cn.hrlly.tao2shou.other.Config;
import cn.hrlly.tao2shou.callback.MyRequireListCallback;
import cn.hrlly.tao2shou.domain.RequireList;
import cn.hrlly.tao2shou.listener.OnMyRequireListListener;
import cn.hrlly.tao2shou.utils.CacheUtil;

/**
 * User: gengliang
 * Date: 2016-01-29
 * Time: 21:12
 */

public class MyRequireListBizImpl implements MyRequireListBiz {

    private OnMyRequireListListener onMyRequireListListener;
    private CacheUtil cacheUtil;

    public MyRequireListBizImpl(OnMyRequireListListener onMyRequireListListener,Context context){
        this.onMyRequireListListener=onMyRequireListListener;
        this.cacheUtil=new CacheUtil(context);
    }

    @Override
    public void getNetMyRequireList() {
        OkHttpUtils
                .post()
                .url(Config.key_url)
                .addParams(Config.key_action,Config.action_my_require_list)
                .build()
                .execute(new MyRequireListCallback(onMyRequireListListener));
    }

    @Override
    public void saveCacheMyRequireList(RequireList requireList) {
        cacheUtil.putPublishRequire(requireList);
    }

    @Override
    public RequireList getCacheMyRequireList() {
        RequireList requireList=cacheUtil.getPublishRequire();
        return requireList;
    }
}
